package practice.hot100;

public class Solution36 {
    public boolean isValidSudoku(char[][] board) {
        boolean[][] rowd = new boolean[9][10];
        boolean[][] cold = new boolean[9][10];
        boolean[][][] matd = new boolean[3][3][10];
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length; j++) {
                if (board[i][j] == '.') continue;
                int num = (int) (board[i][j] - '0');
                if (rowd[i][num]) return false;
                if (cold[j][num]) return false;
                if (matd[i / 3][j / 3][num]) return false;
                rowd[i][num] = true;
                cold[j][num] = true;
                matd[i / 3][j / 3][num] = true;
            }
        }
        return true;
    }
}
